Copyright: K. Nishita.
Citation: K. Nishita.


NviewLib Version 1.1.5 Help Contents

Features

Contributors

Usage

NViewLib Functions

NviewL16.dll (16 bit)

Delphi

VB

NviewLib.dll (32 bit)

Delphi

VB

Obtaining an Update Version

Contact Information

Legal Notice


Whats New
Features

Version 1.1.5 has following features:

1). Support more graphic format: JPG, JIF, GIF, BMP, DIB, RLE, TGA, PCX.

2). Save as JPG.  This function has some limitation.

3). Progress Dialog can show in 8 different languages and customize.

4). One function call can load all the supported format.

5). Little bit better error handling.  Not much, though...

6). Delphi and VB can use the same dll.

7). Detect JPG and GIF by parsing file(Not extension).

8). More accurate integer implementation.


Contributors

Jacques Nomssi Nzali	PasJpeg & updated routine

Jim Shanton 	Memory Leaks

Francisco Purriños 	Spanish Translation

Osvaldo Nobuo Cawamura 	Portuguese Translation

Peter Beddig 	German Translation

Edwin van Driel	Dutch Translation

Enrico 	Italian Translation

Kenji Sato 	Japanese version beta test

Pommereau Franck 	French Translation

Mike Young 	Delphi Example

Edward Lyk 	C++ Bulder Example

Ralf Reiss	VB Example

Vino Rodrigues	Delphi VCL


LEGAL NOTICE

This dll is copyrighted by K. Nishita and can be freely distributed ONLY IF YOU SEND ME AN E-MAIL to nviewlib@freeware.freeservers.com.

<<DISCLAIMER OF WARRANTY>>

THIS SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" AND WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED.  BECAUSE OF THE VARIOUS HARDWARE AND SOFTWARE ENVIRONMENTS INTO WHICH THIS PROGRAM MAY BE PUT, NO WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE IS OFFERED.

WHILE I HAVE MADE EVERY EFFORT TO TEST THE PRODUCT IN A WIDE VARIETY OF OPERATING ENVIRONMENTS, GOOD PROCEDURE DICTATES THAT ANY PROGRAM BE THOROUGHLY TESTED WITH NON-CRITICAL DATA BEFORE RELYING ON IT.  THE USER MUST ASSUME THE ENTIRE RISK OF USING THIS SOFTWARE.

***** LEGAL NOTICE for GIF Format ************************************

By US courts, UniSys Inc. (the inventors of the LZW file

format used by GIF) and Compuserve, who are the registered users

of the format. You will need to obtain a license from them before using this

dll in any product to be sold for profit including shareware.

However, freeware is exempt from this requirement.

***** LEGAL NOTICE for GIF Format ************************************

Jpeg encode and decode:

This Work is based on the work of Meister Bildbetrachter and Jacques Nomssi Nzali, who wrote Pascal version of The Independent JPEG Group C library for JPEG encoding and decoding, rev 6a. You can download his source code from ftp://druckfix.physik.tu-chemnitz.de/pub/nv/.


Contact Information

If you have any question, need technical help, or have comments, please send me an e-mail to nviewlib@freeware.freeservers.com.

K. Nishita

e-mail: nviewlib@freeware.freeservers.com

http://freeware.freeservers.com

Update version can be downloaded from this site.


Usage for Delphi 1.0
NviewL16.dll (16 bit)	Usage for Delphi 1.0:

You can display JPG, JIF, GIF, BMP, DIB, RLE, TGA and PCX format pictures.  In order to display a picture, do following:

First declare functions in NviewL16.dll as:

function NViewLibSetLanguage(Lang: PChar): bool; external 'NviewL16.dll';

Procedure NViewLibSetCustomLang(pProgress,pError, pLoad, pErrLoad, pWarning : PChar); external 'NviewL16.dll';

function NViewLibLoad(FileName : PChar; ShowProgress: BooLean):hbitmap; external 'NviewL16.dll';

function NViewLibSaveAsJPG(Quality:Integer; FileName: PChar):bool; external 'NviewL16.dll';

If you want to show the progress dialog

Image1.Picture.Bitmap.Handle:= NViewLibLoad('fig.jpg', TRUE);

Otherwise,

Image1.Picture.Bitmap.Handle:= NViewLibLoad('fig.jpg', FALSE);

To set language, do

a:=NViewLibSetLanguage(PChar('Japanese'));

If your language is supported, this function will return TRUE, otherwise FALSE.

Following languages are currently supported;

English

German

Dutch

Portuguese

Spanish

Japanese

Italian

French

If you can not find your language or you do not like the built-in messages, you can still customize like,

NViewLibSetLanguage(PChar('custom'));

NViewLibSetCustomLang(pProgress,pError, pLoad, pErrLoad, pWarning);

pProgress is "Progress", pError is "Error", pLoad is "Loading", pErrorLoad is "Error Loading", and pWarning is "Warning" in English built-in message.

Note: Japanese can only be shown in the system which has J/Windows 3.1X.

Saving as Jpeg is little tricky...  You CANNOT save GIF and PCX files as jpg using

NViewLibSaveAsJPG, but you can still save them if you save them to file as bitmap and load bitmap and save as jpg like this,

// Try NViewLibSaveAsJPG first

if not NViewLibSaveAsJPG(80, 'junk.jpg') then

begin

//If NViewLibSaveAsJPG did not then work save as bitmap.

Image1.picture.savetofile('~temp.bmp');

//Load the bitmap

Image1.Picture.Bitmap.Handle:= NViewLibLoad('~temp.bmp',false);

//Save the bitmap as jpeg with 80% of the original picture quality

NViewLibSaveAsJPG(80, 'junk.jpg');

//Delete the bitmap from hard drive and done!

DeleteFile('~temp.bmp');

end;

The jpg picture quality can be between 0~100.  The greater the value, the better the quality is, but the file will be bigger.


Usage for VB (16bit)
NviewL16.dll (16 bit)	Usage for VB (16 bit):

You can display JPG, JIF, GIF, BMP, DIB, RLE, TGA and PCX format pictures.  In order to display a picture, do following:

First declare functions in NviewL16.dll as:

Declare Function NViewLibLoad Lib "NViewL16.dll" (ByVal filename As String, ByVal a As Integer) As Integer

Declare Function NViewLibSaveAsJPG Lib "NViewL16.dll" (ByVal Quality As Integer, ByVal filename As String) As Integer

Declare Function NViewLibSetLanguage Lib "NViewL16.dll" (ByVal Language As String) As Integer

Declare Sub NViewLibSetCustomLang Lib "NViewL16.dll" (ByVal pProgress As String, ByVal pError As String, ByVal pLoad As String, ByVal pErrLoad As String, ByVal pWarning As String)

Declare Function SelectObject Lib "GDI" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer

Declare Function DeleteObject Lib "GDI" (ByVal hObject As Integer) As Integer

Declare Function CreateCompatibleDC Lib "GDI" (ByVal hDC As Integer) As Integer

Declare Function BitBlt Lib "GDI" (ByVal hDestDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal XSrc As Integer, ByVal YSrc As Integer, ByVal dwRop As Long) As Integer

Declare Function DeleteDC Lib "GDI" (ByVal hDC As Integer) As Integer

Declare Function CreateCompatibleBitmap Lib "GDI" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer

Declare Function StretchBlt% Lib "GDI" (ByVal hDC%, ByVal X%, ByVal Y%, ByVal nWidth%, ByVal nHeight%, ByVal hSrcDC%, ByVal XSrc%, ByVal YSrc%, ByVal nSrcWidth%, ByVal nSrcHeight%, ByVal dwRop&)

Declare Function GetObj Lib "GDI" Alias "GetObject" (ByVal hObject As Integer, ByVal nCount As Integer, bmp As Any) As Integer

Type BITMAP '14 bytes

    bmType As Integer

    bmWidth As Integer

    bmHeight As Integer

    bmWidthBytes As Integer

    bmPlanes As String * 1

    bmBitsPixel As String * 1

    bmBits As Long

End Type

Create a subroutine:

Sub NViewLibShowPicutre(picture1 As Control, filename As String, ShowProgress As Integer)

Dim ShadowDC As Long, a As Long, di As Long, Pwidth As Long, Pheight As Long

With picture1

.ScaleMode = 3

.AutoRedraw = True

.Cls

.Refresh

ShadowDC = CreateCompatibleDC(.hDC)

a = NViewLibLoad(filename, ShowProgress)

'Retrieve bitmap to get width (bmp.bmWidth) & height (bmp.bmHeight)

Success = GetObj(a, Len(bmp), bmp)

Pwidth = (bmp.bmWidth + 4) * Screen.TwipsPerPixelX

Pheight = (bmp.bmHeight + 4) * Screen.TwipsPerPixelX

.Width = Pwidth

.Height = Pheight

label2 = .Width

b = SelectObject(ShadowDC, a)

'You can use either BitBlt or StretchBlt. I heard StretchBlt is faster, but I do not know...

'di = BitBlt(picture1.hDC, 0, 0, picture1.Width, picture1.Height, ShadowDC, 0, 0, &HCC0020)

di = StretchBlt(.hDC, 0, 0, Pwidth, Pheight, ShadowDC, 0, 0, Pwidth, Pheight, &HCC0020)

di = SelectObject(ShadowDC, b)

di = DeleteObject(b)

di = DeleteDC(ShadowDC)

.Refresh

End With

End Sub

If you want to show progress dialog call above subroutine as:

NViewLibShowPicutre picture1, "cat.gif", 1

Otherwise

NViewLibShowPicutre picture1, "cat.gif", 0.

To set language, do

a = NViewLibSetLanguage("Japanese")

If your language is supported, this function will return 1, otherwise 0.

Following languages are currently supported;

English

German

Dutch

Portuguese

Spanish

Japanese

Italian

French.

If you can not find your language or you do not like the built-in messages, you can still customize like,

NViewLibSetLanguage("custom")

NViewLibSetCustomLang pProgress pError  pLoad  pErrLoad  pWarning

pProgress is "Progress", pError is "Error", pLoad is "Loading", pErrorLoad is "Error Loading", and pWarning is "Warning" in English built-in message.

Note: Japanese can only be shown in the system which has J/Windows 95/NT.

Saving as Jpeg is little tricky...  You CANNOT save GIF and PCX files as jpg using

NViewLibSaveAsJPG, but you can still save them if you save them to file as bitmap and load bitmap and save as jpg

Create a subroutine as:

Sub NviewLibSave(JpegQuality As Integer, filename As String)

On Error Resume Next  'This line is very important...

Dim a As Integer

a = NViewLibSaveAsJPG(JpegQuality, filename)

If a = 0 Then

SavePicture picture1.Image, "~temp.BMP"

a = NViewLibLoad("~temp.BMP", 0)

a = NViewLibSaveAsJPG(80, filename)

Kill "~temp.bmp"

End If

End Sub

Call above subroutine as

NviewLibSave(80, junk.jpg)

Also, the jpg picture quality can be between 0~100.  The greater the value, the better the quality is, but the file will be bigger.


Usage for Delphi 2.0
NviewLib.dll (32 bit)	Usage for Delphi 2.0:

You can display JPG, JIF, GIF, BMP, DIB, RLE, TGA and PCX format pictures.  In order to display a picture, do following:

First declare functions in NviewLib.dll as:

function NViewLibSetLanguage(Lang: PChar): bool; Stdcall; external 'NViewLib.dll';

Procedure NViewLibSetCustomLang(pProgress,pError, pLoad, pErrLoad, pWarning : PChar); Stdcall; external 'NViewLib.dll';

function NViewLibLoad(FileName : PChar; ShowProgress: BooLean):hbitmap; Stdcall; external 'NViewLib.dll';

function NViewLibSaveAsJPG(Quality:Integer; FileName: PChar):bool; Stdcall; external 'NViewLib.dll';

function Load_JPG(FileName : PChar; ShowProgress: BooLean):hbitmap; Stdcall; external 'NViewLib.dll';

function Load_GIF(FileName : PChar; ShowProgress: BooLean):hbitmap; Stdcall; external 'NViewLib.dll';

To load picture, you can still use old way like,

Call functions as following if you want to show progress dialog...

Image1.Picture.Bitmap.Handle:= Load_JPG('fig.jpg', TRUE);

if you do not want to show progress dialog...

Image1.Picture.Bitmap.Handle:= Load_GIF('fig.GIF', False);

But if you use new way, you can load JPG, JIF, GIF, BMP, DIB, RLE, TGA and PCX format pictures like this,

If you want to show the progress dialog

Image1.Picture.Bitmap.Handle:= NViewLibLoad('fig.jpg', TRUE);

Otherwise,

Image1.Picture.Bitmap.Handle:= NViewLibLoad('fig.jpg', FALSE);

Best of all, you do not have to check extension any more, and only one function all do everything!  Since Jpeg and GIF files are detected by parsing the file, the file extension does not have to be jpg, jif, or gif.

To set language, do

a:=NViewLibSetLanguage(PChar('Japanese'));

If your language is supported, this function will return TRUE, otherwise FALSE.

Following languages are currently supported;

English

German

Dutch

Portuguese

Spanish

Japanese

Italian

French

If you can not find your language or you do not like the built-in messages, you can still customize like,

NViewLibSetLanguage(PChar('custom'));

NViewLibSetCustomLang(pProgress,pError, pLoad, pErrLoad, pWarning);

pProgress is "Progress", pError is "Error", pLoad is "Loading", pErrorLoad is "Error Loading", and pWarning is "Warning" in English built-in message.

Note: Japanese can only be shown in the system which has J/Windows 95/NT.

Saving as Jpeg is little tricky...  You CANNOT save GIF and PCX files as jpg using

NViewLibSaveAsJPG, but you can still save them if you save them to file as bitmap and load bitmap and save as jpg like this,

// Try NViewLibSaveAsJPG first

if not NViewLibSaveAsJPG(80, 'junk.jpg') then

begin

//If NViewLibSaveAsJPG did not then work save as bitmap.

Image1.picture.savetofile('~temp.bmp');

//Load the bitmap

Image1.Picture.Bitmap.Handle:= NViewLibLoad('~temp.bmp',false);

//Save the bitmap as jpeg with 80% of the original picture quality

NViewLibSaveAsJPG(80, 'junk.jpg');

//Delete the bitmap from hard drive and done!

DeleteFile('~temp.bmp');

end;

The jpg picture quality can be between 0~100.  The greater the value, the better the quality is, but the file will be bigger.


Usage for VB (32bit)
NviewLib.dll (32 bit)	Usage for VB (32 bit):

You can display JPG, JIF, GIF, BMP, DIB, RLE, TGA and PCX format pictures.  In order to display a picture, do following:

First declare functions in NviewLib.dll as:

Declare Function Load_JPG Lib "NViewLib.dll" (ByVal FileName As String, ByVal a As Integer) As Long

Declare Function Load_GIF Lib "NViewLib.dll" (ByVal FileName As String, ByVal a As Integer) As Long

Declare Function NViewLibLoad Lib "NViewLib.dll" (ByVal FileName As String, ByVal a As Integer) As Long

Declare Function NViewLibSaveAsJPG Lib "NViewLib.dll" (ByVal Quality As Integer, ByVal FileName As String) As Integer

Declare Function NViewLibSetLanguage Lib "NViewLib.dll" (ByVal Language As String) As Integer

Declare Sub NViewLibSetCustomLang Lib "NViewLib.dll" (ByVal pProgress As String, ByVal pError As String, ByVal pLoad As String, ByVal pErrLoad As String, ByVal pWarning As String)

Declare Function GetWidth Lib "NViewLib.dll" () As Integer

Declare Function GetHeight Lib "NViewLib.dll" () As Integer

Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long

Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long

Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long

Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long

Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long

To load picture, you can still use old way like,

Call functions as following if you want to show progress dialog...

With picture1

.ScaleMode = 3

.AutoRedraw = True

.Cls

.Refresh

ShadowDC = CreateCompatibleDC(.hdc)

a = Load_JPG("FIG.JPG", 1)

Xtwips& = Screen.TwipsPerPixelX

Ytwips& = Screen.TwipsPerPixelY

Pwidth = (GetWidth() + 4) * Screen.TwipsPerPixelX

Pheight = (GetHeight() + 4) * Screen.TwipsPerPixelY

.Width = Pwidth

.Height = Pheight

b = SelectObject(ShadowDC, a)

'You can use either BitBlt or StretchBlt. I heard StretchBlt is faster, but I do not know...

'di = BitBlt(picture1.hdc, 0, 0, picture1.Width, picture1.Height, ShadowDC, 0, 0, &HCC0020)

di = StretchBlt(.hdc, 0, 0, Pwidth, Pheight, ShadowDC, 0, 0, Pwidth, Pheight, &HCC0020)

di = SelectObject(ShadowDC, b)

di = DeleteObject(b)

di = DeleteDC(ShadowDC)

.Refresh

End With

if you do not want to show progress dialog...

With picture1

.ScaleMode = 3

.AutoRedraw = True

.Cls

.Refresh

ShadowDC = CreateCompatibleDC(.hdc)

a = Load_GIF("FIG.gif", 0)

Xtwips& = Screen.TwipsPerPixelX

Ytwips& = Screen.TwipsPerPixelY

Pwidth = (GetWidth() + 4) * Screen.TwipsPerPixelX

Pheight = (GetHeight() + 4) * Screen.TwipsPerPixelY

.Width = Pwidth

.Height = Pheight

b = SelectObject(ShadowDC, a)

'You can use either BitBlt or StretchBlt. I heard StretchBlt is faster, but I do not know...

'di = BitBlt(picture1.hdc, 0, 0, picture1.Width, picture1.Height, ShadowDC, 0, 0, &HCC0020)

di = StretchBlt(.hdc, 0, 0, Pwidth, Pheight, ShadowDC, 0, 0, Pwidth, Pheight, &HCC0020)

di = SelectObject(ShadowDC, b)

di = DeleteObject(b)

di = DeleteDC(ShadowDC)

.Refresh

End With

But if you use new way, you can load JPG, JIF, GIF, BMP, DIB, RLE, TGA and PCX format pictures as followings:

Create a subroutine:

Sub NViewLibShowPicutre(picture1 As Control, filename As String, ShowProgress As Integer)

Dim ShadowDC As Long, a As Long, di As Long, Pwidth As Long, Pheight As Long

With picture1

.ScaleMode = 3

.AutoRedraw = True

.Cls

.Refresh

ShadowDC = CreateCompatibleDC(.hdc)

a = NViewLibLoad(filename, ShowProgress)

Pwidth = (GetWidth() + 4) * Screen.TwipsPerPixelX

Pheight = (GetHeight() + 4) * Screen.TwipsPerPixelY

.Width = Pwidth

.Height = Pheight

b = SelectObject(ShadowDC, a)

'You can use either BitBlt or StretchBlt. I heard StretchBlt is faster, but I do not know...

'di = BitBlt(picture1.hdc, 0, 0, picture1.Width, picture1.Height, ShadowDC, 0, 0, &HCC0020)

di = StretchBlt(.hdc, 0, 0, Pwidth, Pheight, ShadowDC, 0, 0, Pwidth, Pheight, &HCC0020)

di = SelectObject(ShadowDC, b)

di = DeleteObject(b)

di = DeleteDC(ShadowDC)

.Refresh

End With

End Sub

If you want to show progress dialog call above subroutine as:

NViewLibShowPicutre picture1, "cat.gif", 1

Otherwise

NViewLibShowPicutre picture1, "cat.gig", 0.

Best of all, you do not have to check extension any more, and only one function all do everything!  Since Jpeg and GIF files are detected by parsing the file, the file extension does not have to be jpg, jif, or gif.

To set language, do

a = NViewLibSetLanguage("Japanese")

If your language is supported, this function will return 1, otherwise 0.

Following languages are currently supported;

English

German

Dutch

Portuguese

Spanish

Japanese

Italian

French.

If you can not find your language or you do not like the built-in messages, you can still customize like,

NViewLibSetLanguage("custom")

NViewLibSetCustomLang pProgress pError  pLoad  pErrLoad  pWarning

pProgress is "Progress", pError is "Error", pLoad is "Loading", pErrorLoad is "Error Loading", and pWarning is "Warning" in English built-in message.

Note: Japanese can only be shown in the system which has J/Windows 95/NT.

Saving as Jpeg is little tricky...  You CANNOT save GIF and PCX files as jpg using

NViewLibSaveAsJPG, but you can still save them if you save them to file as bitmap and load bitmap and save as jpg

Create a subroutine as:

Sub NviewLibSave(JpegQuality As Integer, filename As String)

On Error Resume Next  'This line is very important...

Dim a As Integer

a = NViewLibSaveAsJPG(JpegQuality, filename)

If a = 0 Then

SavePicture picture1.Image, "~temp.BMP"

a = NViewLibLoad("~temp.BMP", 0)

a = NViewLibSaveAsJPG(80, filename)

Kill "~temp.bmp"

End If

End Sub

Call above subroutine as

NviewLibSave(80, junk.jpg)

Also, the jpg picture quality can be between 0~100.  The greater the value, the better the quality is, but the file will be bigger.


Obtaining an Update Version

Update version can be downloaded from http://freeware.freeservers.com.


NViewLib Functions

Followings are the available functions.

Declare Function NViewLibLoad Lib "NViewLib.dll" (ByVal FileName As String, ByVal a As Integer) As Long

Declare Function NViewLibSaveAsJPG Lib "NViewLib.dll" (ByVal Quality As Integer, ByVal FileName As String) As Integer

Declare Function NViewLibSetLanguage Lib "NViewLib.dll" (ByVal Language As String) As Integer

Declare Sub NViewLibSetCustomLang Lib "NViewLib.dll" (ByVal pProgress As String, ByVal pError As String, ByVal pLoad As String, ByVal pErrLoad As String, ByVal pWarning As String)

32 bit Version Only:

Declare Function Load_JPG Lib "NViewLib.dll" (ByVal FileName As String, ByVal a As Integer) As Long

Declare Function Load_GIF Lib "NViewLib.dll" (ByVal FileName As String, ByVal a As Integer) As Long

Declare Function GetWidth Lib "NViewLib.dll" () As Integer

Declare Function GetHeight Lib "NViewLib.dll" () As Integer